package blacknWhite.Libraries;
/*******************************************************************************
 * Copyright (C) 2009 Google Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 ******************************************************************************/


import java.net.URL;
import java.text.MessageFormat;

/**
 * Signal that an unexpected (exceptional) response was received from a remote
 * server.
 * 
*
 */
public class HttpUrlException extends CheckoutException {
  /**
	 * 
	 */
	private static final long serialVersionUID = 1L;
private final URL toUrl;
  private final int responseCode;
  private final Object triedToSend;
  private final Object responseMessage;  
  
  public HttpUrlException(URL toUrl, int responseCode, Object sent, Object received, Throwable causedBy) {
    super(causedBy);
    this.toUrl = toUrl;
    this.responseCode = responseCode;
    this.triedToSend = sent;
    this.responseMessage = received;
  }

  public static final String SEND_AND_RECEIVE_DEBUGGING_STRING =
	    "Response Code:\t{0}\n"
	    + "With Url:\t[ {1} ]\n"
	    + "Request:\t[ {2} ]\n"
	    + "Response:\t[ {3} ]";
  
  @Override
  public String getMessage() {
    return MessageFormat.format(SEND_AND_RECEIVE_DEBUGGING_STRING,
        responseCode, toUrl, triedToSend, responseMessage);
  }
  
  public int getCode() {
    return responseCode;
  }
  
  public String getSent() {
    return triedToSend.toString();
  }

  public String getResponse() {
    return responseMessage.toString();
  }  
}
